<template>
  <van-picker
    title="性别"
    show-toolbar
    :columns="columns"
    :default-index="value"
    @confirm="onConfirm"
    @cancel="onCancel"
  />
</template>

<script>
import { modefyUserProfile } from '@/api/login'
export default {
  props: ['value'],
  data () {
    return {
      columns: ['男', '女']
    }
  },
  methods: {
    onConfirm (value, index) {
      this.modefyNameFn(index)
    },
    onCancel () {
      this.$emit('close')
    },
    async modefyNameFn (index) {
      this.$toast.loading({
        message: '修改中...',
        forbidClick: true,
        duration: 0
      })
      try {
        await modefyUserProfile({
          gender: index
        })
        this.$emit('input', index)
        this.$emit('close')
        this.$toast('修改成功')
      } catch (error) {
        console.log(error)
        this.$toast('修改失败')
      }
    }
  }
}
</script>

<style>
</style>
